16. Geometry and Visualization

Geometry and Visualization

You’ve seen some of the LIBRARIES that the Google Maps APIs has to offer - let’s explore two of them, the Geometry library and the Visualizations library.

Geometry

The geometry library can be loaded by specifying “libraries=geometry” when loading the JavaScript API in your site. This library does not contain any classes, but rather, contains methods within three namespaces:

  • spherical contains spherical geometry utilities in order to allow you to compute angles, distances, headings, and areas in a spherical plane. Some examples of this are computeArea, which takes in a polygon path (as a set of lat/lng pairs) and gets the area, or computeDistanceBetween, which takes in two lat/lng points and calculates the distance between them on the earth, taking into account the earth’s curvature.
  • poly contains utility functions for computations involving polygons and polylines, to allow you determine if a point is within a polygon, or if a point lies within a specified distance of a polyline.
  • encoding contains utilities for encoding and decoding polyline paths according to the Encoded Polyline Algorithm.

Visualization

The visualization library can be loaded by specifying “libraries=visualizations” when loading the JavaScript API in your site. This library contains one class, the “HeatmapLayer” class, which allows you to visualize data intensity at a given geographical point. A few pointers:

  • You’ll usually have a dataset to visualize when using this class - you can store the data client-side, but it may reduce the performance of your site if the dataset is large
  • You can also store the data server side and access it dynamically, but you will sacrifice some client side data manipulation options

There are two more libraries, which we’ll cover in more detail in the course - Places, and Drawing!